package initialize

import (
	"github.com/winksai/utils/mysql"
	"github.com/winksai/utils/nacos"
	"github.com/winksai/utils/redis"
	"github.com/winksai/utils/viper"
	"log"
	"user_srv/global"
)

func init() {
	Viper()
	Nacos()
	Mysql()
	Redis()

}
func Viper() {
	viper.Viper("./dev.yaml")
}
func Nacos() {
	getNacos := viper.GetNacos()
	_, err := nacos.Nacos(getNacos.NameSpace, getNacos.Username, getNacos.Password, getNacos.Addr, getNacos.Port, getNacos.DataID, getNacos.Group)
	if err != nil {
		log.Println(err)
		return
	}
}

// 初始化mysql封装
func Mysql() {
	configs := nacos.GetConfig()
	config := configs.Mysql
	db := mysql.InitMysql(config.User, config.Password, config.Host, config.Database, config.Port)
	global.DB = db
}

// 初始化redis封装
func Redis() {
	configs := nacos.GetConfig()
	config := configs.Redis
	db := redis.InitRedis(config.Host, config.Password, 0)
	global.RedisClient = db
}
